# 简单评估脚本
import torch
from app.models.moisture_model import MoistureModel
from app.utils.data_loader import get_dataloader
from config.settings import CHECKPOINT_DIR

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = MoistureModel().to(device)
model.load_state_dict(torch.load(CHECKPOINT_DIR / "moisture_best.pth"))
model.eval()

test_loader = get_dataloader("test", "moisture", shuffle=False)

correct = 0
total = 0
with torch.no_grad():
    for inputs, labels in test_loader:
        inputs, labels = inputs.to(device), labels.to(device)
        outputs = model(inputs)
        _, predicted = torch.max(outputs, 1)
        total += labels.size(0)
        correct += (predicted == labels).sum().item()

print(f"Test Accuracy: {correct / total:.4f}")
# 类似pest